{$ifdef interface}
type
  TAppDataTab = class
    public
      rows_per_page : word;
      rows_per_page_default : word;
      page : word;
      pages : word;
      table : string;
      database : string;
      grid : TAppDataGrid;
      constructor Create;
      procedure loadGrid;
  end;

var data : TAppDataTab;
{$endif}

{$ifdef implementation}

constructor TAppDataTab.Create;
begin
  inherited Create;
  try rows_per_page_default := strtoint(_config.data.getValueFor('tab_data_limit'));
  except end;
  if (rows_per_page_default = 0) then
  begin
    rows_per_page := TAB_DATA_LIMIT_DEFAULT;
    rows_per_page_default := rows_per_page;
  end
    else rows_per_page := rows_per_page_default;
  page := 0;
  pages := 0;
  table:='';
end;

procedure TAppDataTab.loadGrid;
var sql:string;
begin
  sql:=format('SELECT * FROM `%s`.`%s`',[self.database,self.table]);
  if (self.rows_per_page > 0) then
  begin
    if (self.page > 0) then
    begin
      sql := sql + ' LIMIT ' + inttostr(self.page * self.rows_per_page) + ','
                   + inttostr((self.page+1) * self.rows_per_page);
    end else sql := sql + ' LIMIT ' + inttostr(self.rows_per_page);
  end;
  _data.log.debug(sql);
  db.loadDataFromSQL(sql,self.grid);
  //
end;

{$endif}

{$ifdef initialization}
  data := TAppDataTab.Create;
{$endif}
